package com.entrogy.utils;



/**
 * @Author 许红松
 * @date 2019/4/25 0025 下午 3:22
 * 比较两个字符串中相同元素 并返回
 */
public class Contains {

    public static String contains(String str1,String str2) {
        String[] arr1 = str1.split(",") ;
        String[] arr2 = str2.split(",") ;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr2.length; i++){
            for (int j = 0; j < arr1.length; j++){
                if (arr1[j].equals(arr2[i])){
                    sb.append(arr1[j] + ",") ;
                }
            }
        }
        return  sb.toString();
    }

    public static Boolean contains2(String str1,String str2) {
        Boolean a=false;
        String[] arr1 = str1.split(",") ;
        String[] arr2 = str2.split(",") ;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr2.length; i++){
            for (int j = 0; j < arr1.length; j++){
                if (arr1[j].equals(arr2[i])){
                    sb.append(arr1[j] + ",") ;
                }
            }
        }

        if (sb.toString().split(",").toString().length()>0){
            a=true;
        }
        return a;
    }

    public static Boolean contaiins(String str1,String str2) {
        String[] arr1 = str1.split(",");
        Boolean m=false;
        int a = arr1.length;
        if (a > 1) {
            for (int i = arr1.length - 1; i >= 0; i--) {
                if (str2.contains(arr1[i])) {
                    return true;
                }
            }
        }else{
            if (str2.contains(str1)) {
                return true;
            }
        }
        return m;
    }

    public static String contaiins2(String str1,String str2) {
        String[] arr1 = str1.split(",");
        Boolean m=false;
        int a = arr1.length;
        String stringf="";
        if (a > 1) {
            for (int i = arr1.length - 1; i >= 0; i--) {
                if (str2.contains(arr1[i])) {
                    stringf+=arr1[i]+",";
                }
            }
        }
        else{
            stringf=str1;
        }
        return stringf;
    }

}
